package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbUserSrwp;
import com.shenmazong.servereduresume.service.TbUserSrwpService;
import com.shenmazong.servereduresume.mapper.TbUserSrwpMapper;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import com.shenmazong.vo.SrwpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class TbUserSrwpServiceImpl extends ServiceImpl<TbUserSrwpMapper, TbUserSrwp>
implements TbUserSrwpService{

    @Autowired
    private TbUserSrwpMapper tbUserSrwpMapper;
    @Override
    public ResultResponse getMySrwp(ListParamVo listParamVo) {
        Page<SrwpVo> page = new Page<>(listParamVo.getCurrent(),listParamVo.getSize());
        page=tbUserSrwpMapper.getMySrwp(page, (Long) listParamVo.getParamMap().get("userId"));
        return ResultResponse.SUCCESS(page);
    }

    @Override
    public ResultResponse saveMySrwp(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()==0){
            return ResultResponse.FAILED("至少收藏一个简历");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                tbUserSrwpMapper.insert(new TbUserSrwp(id, (Long) batchChooseIdVo.getParamMap().get("userId"),null,null,null));
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteMySrwp(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()==0){
            return ResultResponse.FAILED("至少收藏一个简历");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                TbUserSrwp tbUserSrwp = tbUserSrwpMapper.selectById(id);
                tbUserSrwp.setDeleteFlag(true);
                tbUserSrwpMapper.updateById(tbUserSrwp);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




